package com.tiancheng.trade.commom.web.configuration;

import com.tiancheng.trade.commom.core.utils.SpringContextHolder;
import com.tiancheng.trade.commom.web.http.PlatformRequest;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
@EnableConfigurationProperties(PlatformRequestProperties.class)
@AutoConfigureAfter({PlatformRequestProperties.class, SpringContextHolder.class})
@ConditionalOnProperty(prefix = "platform.request", value = {"client-id", "client-secret", "server-path"})
public class PlatformRequestAutoConfiguration {
    /**
     * 服务请求bean
     */
    @Bean
    @ConditionalOnMissingBean
    @DependsOn("springContextHolder")
    public PlatformRequest platformRequest(PlatformRequestProperties platformRequestProperties) {
        return new PlatformRequest(platformRequestProperties);
    }
}
